home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 1 of 3 / CHAPTE23 / EX4.C < prev   
C/C++ Source or Header  |  1995-03-22  |  2KB  |  60 lines

  1. #include <genstub.c>
  2.  
  3. // Menu options.
  4. #include <atomtest.h>
  5.  
  6. // Atom name - constant string.
  7. #define THE_ATOM               "A global atom."
  8.  
  9. LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  10. {
  11.    switch (uMsg)          // Process Windows messages.
  12.    {
  13.        case WM_COMMAND:   // Process menu items.
  14.               switch ( LOWORD( wParam ) )
  15.                   {
  16.                      case IDM_ADDATOM:       // Adds an atom.
  17.                               GlobalAddAtom( THE_ATOM );
  18.                               InvalidateRect( hWnd, NULL, TRUE );
  19.                               UpdateWindow( hWnd );
  20.                               break;
  21.                      case IDM_DELETEATOM:    // Delete an atom.
  22.                               if ( !GlobalFindAtom( THE_ATOM ) )
  23.                                  MessageBox( hWnd, "Atom no longer exists.", "Error Message", MB_OK );
  24.                               else 
  25.                                  GlobalDeleteAtom( GlobalFindAtom(THE_ATOM) );
  26.                               InvalidateRect( hWnd, NULL, TRUE );
  27.                               UpdateWindow( hWnd );
  28.                               break;
  29.                      case IDM_EXIT:
  30.                               DestroyWindow( hWnd );
  31.                               break;
  32.                   }
  33.                   break;
  34.       case WM_PAINT:
  35.             {   // Show the results of searching for an atom.
  36.                 ATOM aAnAtom;
  37.                 PAINTSTRUCT ps;
  38.                 char szWorkArea[33], szBuffer[128];
  39.                 BeginPaint( hWnd, &ps );
  40.                 if (aAnAtom = GlobalFindAtom( THE_ATOM )) {
  41.                    GlobalGetAtomName( aAnAtom, szWorkArea, 32 );
  42.                    wsprintf( szBuffer, "Atom '%s' was found.", szWorkArea );
  43.                 }
  44.                 else
  45.                    lstrcpy( szBuffer, "Atom must be added." );
  46.                 TextOut( ps.hdc, 0, 0, szBuffer, lstrlen( szBuffer ) );
  47.                 EndPaint( hWnd, &ps );
  48.             }
  49.             break ;
  50.       case WM_DESTROY: 
  51.             PostQuitMessage( 0 );
  52.       break ;
  53.       default:
  54.          return DefWindowProc( hWnd, uMsg, wParam, lParam );
  55.    }
  56.    return( 0L ) ;
  57. }
  58.  
  59. #include <about.c>
  60.